package com.example.zhongshuishi.controller;


import com.example.zhongshuishi.service.SmsService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sms")
@RequiredArgsConstructor
public class SmsController {
   private final SmsService smsService;

    @GetMapping("/send")
    public ResponseEntity<?> sendCode(@RequestParam String phone) {
        if (smsService.sendSmsCode(phone)) {
            return ResponseEntity.ok("验证码发送成功");
        }
        return ResponseEntity.status(500).body("发送失败");
    }

    @PostMapping("/verify")
    public ResponseEntity<?> verifyCode(
            @RequestParam String phone,
            @RequestParam String code
    ) {
        if (smsService.verifyCode(phone, code)) {
            return ResponseEntity.ok("验证成功");
        }
        return ResponseEntity.badRequest().body("验证码错误");
    }
}